package cn.snailhd.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtils {
	private static int grounpIndex =1;
	public static void setGrounpIndex(int index){
		grounpIndex = index;
	}

	
	public static List<String> getList(String input,Pattern pattern){
		List<String> list = new ArrayList();	
		Matcher matcher = pattern.matcher(input);
		while(matcher.find()){
			String str = matcher.group(grounpIndex);
			list.add(str);
		}		
		return list;
	}
	
	public static List<String> getList(String input,Tag...tags){
		List<String> list = new ArrayList();
		
		for(Tag tag:tags){
			for(Pattern pattern:tag.get()){
				List<String> relist  = getList(input, pattern);
					for(String s:relist){
						if(!list.contains(s)){
							list.add(s);
						}
					}
			}			
		}
		
		return list;
	}
	
	public static List<String> getList(String input,String regex){
		Pattern pattern = Pattern.compile(regex);
		return getList(input,pattern);
	}
	
	

}
